﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Freecart_Local_.Classes;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Xml;
using System.Xml.XPath;

namespace Freecart_Local_.Controls
{
    public partial class Cart_Control : System.Web.UI.UserControl
    {
        private Guid _guid;
        public Guid Guid { set { this._guid = value; } get { return this._guid; } }

        protected void Page_Load(object sender, EventArgs e)
        {
            LiteralControl _litctrl = new LiteralControl();
            if (!Page.IsPostBack)
            {
                // Checking if guid exists
                if (Page.Session["guid"] != null)
                {
                    this._guid = (Guid)Page.Session["guid"];

                    // Checking to see if this is a valid guid
                    if (CartManager.isValidGuid(this._guid) == true)
                    {
                        Cart cart = CartManager.FetchCartByGuid(this._guid);

                        GridView gv = new GridView();
                        gv.DataSource = cart.Items.Table;
                        gv.ShowFooter = false;
                        gv.DataBind();

                        this.Controls.Add(gv);
                    }
                    else
                    {
                        // No cart found
                        _litctrl.Text="<br>No cart found";
                    }
                }
                else
                {
                    // No guid found
                }
            }

           this.PlaceHolderMessages.Controls.Add(_litctrl);
        }
    }
}